#include "taskEditor.h"

taskEditor::taskEditor(QWidget *parent) : QDialog( parent )
{
    sheet = new spredsheet( this );

    inputLabel = new QLabel(tr("Input"));
    outputLabel = new QLabel(tr("Output"));
    algoTypeLabel = new QLabel(tr("Algorithm type"));
    optTypeLabel = new QLabel(tr("Optimization type"));

    manualyInputRadio = new QRadioButton(tr("Manual"));
    manualyInputRadio->setChecked( true );
    fromFileInputRadio = new QRadioButton(tr("From file"));

    inputEdit = new QLineEdit();
    inputEdit->setEnabled( false );
    outputEdit = new QLineEdit();
    outputEdit->setEnabled( false );

    inputBrowseButton = new QPushButton(tr("Browse"));
    inputBrowseButton->setEnabled( false );
    outputBrowseButton = new QPushButton(tr("Browse"));
    manualInputButton = new QPushButton(tr("Edit"));

    saveButton = new QPushButton(tr("Save"));
    runButton = new QPushButton(tr("Run"));
    closeButton = new QPushButton(tr("Close"));

    algoritmsBox = new QComboBox();
    algoritmsBox->addItems( algo );
    optimizationsBox = new QComboBox();
    optimizationsBox->addItems( optim );


    inputFileLayout = new QHBoxLayout();
    inputFileLayout->addWidget( inputEdit );
    inputFileLayout->addWidget( inputBrowseButton );

    outputFileLayout = new QHBoxLayout();
    outputFileLayout->addWidget( outputEdit );
    outputFileLayout->addWidget( outputBrowseButton );

    inputLayout = new QVBoxLayout();
    inputLayout->addWidget( inputLabel, 0, Qt::AlignLeft );
    inputLayout->addWidget( manualyInputRadio, 0, Qt::AlignLeft );
    inputLayout->addWidget( manualInputButton, 0, Qt::AlignLeft );
    inputLayout->addWidget( fromFileInputRadio, 0, Qt::AlignLeft );
    inputLayout->addLayout( inputFileLayout );

    outputLayout = new QVBoxLayout();
    outputLayout->addWidget(outputLabel, 0, Qt::AlignLeft);
    outputLayout->addLayout(outputFileLayout);

    paramLayout = new QVBoxLayout();
    paramLayout->addWidget(algoTypeLabel, 0, Qt::AlignLeft);
    paramLayout->addWidget(algoritmsBox, 0, Qt::AlignLeft);
    paramLayout->addWidget(optTypeLabel, 0, Qt::AlignLeft);
    paramLayout->addWidget(optimizationsBox, 0, Qt::AlignLeft);

    buttonsLayout = new QHBoxLayout();
    buttonsLayout->addStretch();
    buttonsLayout->addWidget(saveButton, 0, Qt::AlignRight);
    buttonsLayout->addWidget(runButton, 0, Qt::AlignRight);
    buttonsLayout->addWidget(closeButton, 0, Qt::AlignRight);

    mainLayout = new QVBoxLayout();
    mainLayout->addLayout( inputLayout );
    mainLayout->addLayout( outputLayout );
    mainLayout->addLayout( paramLayout );
    mainLayout->addLayout( buttonsLayout );

    connect( manualyInputRadio, SIGNAL(toggled(bool)), manualInputButton, SLOT(setEnabled(bool)) );
    connect( fromFileInputRadio, SIGNAL(toggled(bool)), inputBrowseButton, SLOT(setEnabled(bool)) );

    connect( manualInputButton, SIGNAL(clicked()), this, SLOT(editInput()) );
    connect( closeButton, SIGNAL(clicked()), this, SLOT(close()) );

    setLayout( mainLayout );
}

void taskEditor::editInput()
{
    sheet->setSize( 10, 4 );
    sheet->exec();
}
